<template>
  <div>
    <div class="content">
      <div class="title">编辑推荐</div>
      <div class="wrap">
      <van-row gutter="2">
  <van-col span="8" v-for="item in list" :key="item.id">
    <router-link :to="'/playlist/'+item.id">
      <div class="item"><div class="tupian"><img :src="item.picUrl" alt=""></div>
    <div class="total">{{ item.playCount | num() }}</div >
      <div class="info">{{ item.name }}</div></div>
    </router-link>
    </van-col>
  </van-row>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div class="main">
      <div class="newsong">最新音乐</div>
      <div class="list">
        <div class="item" v-for="item in newsong" :key="item.id">
          <router-link :to="'/songPage/'+item.id">
            <div class="left">
            <div class="subtitle">{{item.name}}<span>{{item.song.alias[0] }}</span></div>
            <div class="author" v-if="item.song.artists.length>1"><span  v-for="ele in item.song.artists" :key="ele.id" class="ele"> {{ ele.name }}</span>
            - {{ item.song.album.name }}</div>
            <div class="author" v-else><span  v-for="ele in item.song.artists" :key="ele.id" class="ele"> {{ ele.name }}</span>
            - {{ item.song.album.name }}</div>
          </div>
        <div class="right"></div>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      list: [],
      newsong:[]
    }
  },
  created () {
    this.getMusic()
    this.getNewsong()
    
  },

  methods: {
    async getMusic () {
      const { data: res } = await this.$api.getMusic()
      this.list = res.result
    },
    async getNewsong () {
      const { data: res } = await this.$api.getNewsong()
      this.newsong = res.result
    },
   
  },
  filters: {
    num (val) {
      if (!val) {
        return val
      } else {
        return (val / 10000).toFixed(1) + '万'
      }
    }
  }
}
</script>

<style lang="less" scoped>
.content{
  padding-top: 20px;
  .title{
    position: relative;
    font-size: 17px;
    line-height: 20px;
    padding-left: 9px;
    margin-bottom: 14px;
    height: 20px;

  }
  .title::after{
    content: '';
    height: 16px;
    width: 2px;
    background-color: #d33a31;
    position: absolute;
    left: 1px;
  }
}
.wrap{
.item{
  position: relative;
  .tupian{
    width: 123px;
    height: 123px;
    overflow: hidden;
    img{
      width: 100%;
      height: 100%;
    }
}
.total{
  position: absolute;
  top: 2px;
  right: 2px;
  color: white;
}
.info{
  font-size: 13px;
  text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
overflow: hidden;
/*! autoprefixer: off */
-webkit-box-orient: vertical;
/*! autoprefixer: on */
word-break: break-all ;
height: 41px;
line-height: 19px;
}
}
}
.main{
  padding-top: 36px;
  .newsong{
    position: relative;
    font-size: 17px;
    line-height: 20px;
    padding-left: 9px;
    margin-bottom: 14px;
    height: 20px;
  }
  .newsong::after{
    content: '';
    position: absolute;
    height: 16px;
    width: 2px;
    background-color: #d33a31;
    position: absolute;
    left: 1px;
  }

.item{
  display: flex;
  padding: 6px 13px;
  border-bottom: 1px solid #efebeb;
  
  .left{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
    flex: 1;
    .subtitle{
    font-size: 17px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
    span{
      overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
      color: #888;
    margin-left: 4px;
    }
  }
  .author{
    font-size: 12px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
  }
  .ele::after{
    content: ' /';
  }
  .ele:last-child::after{
    content:'' ;
  }
  }
  .right{
    width: .9rem;
  }
}
}

</style>
